/**
 * @file ac_package_operation.h
 * @version 1.0
 * @date August 2024 
 * @author WSH
 *
 * @brief
 *  ac_pkg_t ac_pkg;
 *  ptl_parse_init(&ac_pkg);
 *  ptl_parse_char(&ac_pkg,buffer[len]);
 * 
 * @note
 * @details
 *
 * @Copyright (c) 2024 WSH
 */
#ifndef __AC_PACKAGE_OPERATION_H__
#define __AC_PACKAGE_OPERATION_H__

#include "stdint.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
    uint8_t send_id;
    uint8_t send_sys_id;
    uint8_t rec_id;
    uint8_t rec_sys_id;
    uint8_t type;   // 类型
    uint8_t length; // 长度
}PacketSender_t;

uint16_t  ptl_pack_float32(uint8_t *data ,float fin,uint16_t curr_index);
uint16_t  ptl_pack_uint16(uint8_t *data ,uint16_t u16_in,uint16_t curr_index);
uint16_t  ptl_pack_int16(uint8_t *data ,int16_t u16_in,uint16_t curr_index);
uint16_t  ptl_pack_int32(uint8_t *data ,int data_in,uint16_t curr_index);
uint16_t  ptl_pack_uint32(uint8_t *data ,uint32_t data_in,uint16_t curr_index);

float     ptl_depack_float32(uint8_t *datain,int *index);
uint16_t  ptl_depack_uint16(uint8_t *datain,int *index);
int16_t   ptl_depack_int16(uint8_t *datain,int *index);
int       ptl_depack_int32(uint8_t *datain ,int *index);
uint32_t  ptl_depack_uint32(uint8_t *datain ,uint32_t *index);

uint16_t  ptl_pack_void(uint8_t *data ,uint16_t void_size,uint16_t curr_index);

// 打包协议头
uint16_t ptl_encode_head(PacketSender_t *PacketSender,uint8_t *buffer_out,uint8_t type,uint16_t data_size,uint16_t max_len);

// 打包协议尾(数据入口,数据当前长度,缓存最大长度)-->总长度
uint16_t ptl_encode_tail(uint8_t *buffer_out,uint16_t curr_len,uint16_t max_len);

/*!
* @brief 初始化
* @param PacketSender: 发送器句柄
* @param send_sys_id: 发送系统ID
* @param send_id:     发送id
* @param rec_sys_id:  接收系统ID
* @param rec_id:      接收部件ID
*/
void PacketSenderInit(PacketSender_t *PacketSender,uint8_t send_sys_id,uint8_t send_id,uint8_t rec_sys_id,uint8_t rec_id);

// 协议解析器
#define PTL_DEC_BUFFER 255


typedef struct {
    uint8_t status ;
    uint8_t buffer[PTL_DEC_BUFFER]; // 缓存
    uint16_t curr_count;
    
    PacketSender_t PacketSender; // 系统信息

}ac_pkg_t;

void ptl_parse_init(ac_pkg_t *pac_pkg);

// 解析器
uint8_t ptl_parse_char(ac_pkg_t *pac_pkg,uint8_t char_in);

// 设置监听





#ifdef __cplusplus
}
#endif

#endif //!__AC_PACKAGE_OPERATION_H__
